/**
 * Copyright (c) 2004-2006, Martin Fiedler
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, 
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 **/
 
#include "common.h"
#include "slicehdr.h"
#include "mbmodes.h"


char *_str_mb_type(int mb_type) {
  switch(mb_type) {
    case P_L0_16x16: return "P_L0_16x16";
    case P_L0_L0_16x8: return "P_L0_L0_16x8";
    case P_L0_L0_8x16: return "P_L0_L0_8x16";
    case P_8x8: return "P_8x8";
    case P_8x8ref0: return "P_8x8ref0";
    case I_4x4: return "I_4x4";
    case I_16x16_0_0_0: return "I_16x16_0_0_0";
    case I_16x16_1_0_0: return "I_16x16_1_0_0";
    case I_16x16_2_0_0: return "I_16x16_2_0_0";
    case I_16x16_3_0_0: return "I_16x16_3_0_0";
    case I_16x16_0_1_0: return "I_16x16_0_1_0";
    case I_16x16_1_1_0: return "I_16x16_1_1_0";
    case I_16x16_2_1_0: return "I_16x16_2_1_0";
    case I_16x16_3_1_0: return "I_16x16_3_1_0";
    case I_16x16_0_2_0: return "I_16x16_0_2_0";
    case I_16x16_1_2_0: return "I_16x16_1_2_0";
    case I_16x16_2_2_0: return "I_16x16_2_2_0";
    case I_16x16_3_2_0: return "I_16x16_3_2_0";
    case I_16x16_0_0_1: return "I_16x16_0_0_1";
    case I_16x16_1_0_1: return "I_16x16_1_0_1";
    case I_16x16_2_0_1: return "I_16x16_2_0_1";
    case I_16x16_3_0_1: return "I_16x16_3_0_1";
    case I_16x16_0_1_1: return "I_16x16_0_1_1";
    case I_16x16_1_1_1: return "I_16x16_1_1_1";
    case I_16x16_2_1_1: return "I_16x16_2_1_1";
    case I_16x16_3_1_1: return "I_16x16_3_1_1";
    case I_16x16_0_2_1: return "I_16x16_0_2_1";
    case I_16x16_1_2_1: return "I_16x16_1_2_1";
    case I_16x16_2_2_1: return "I_16x16_2_2_1";
    case I_16x16_3_2_1: return "I_16x16_3_2_1";
    case I_PCM: return "I_PCM";
    case P_Skip: return "P_Skip";
    default: return "n/a";
  }
}

char *_str_sub_mb_type(int sub_mb_type) {
  switch(sub_mb_type) {
    case P_L0_8x8: return "P_L0_8x8";
    case P_L0_8x4: return "P_L0_8x4";
    case P_L0_4x8: return "P_L0_4x8";
    case P_L0_4x4: return "P_L0_4x4";
    default: return "n/a";
  }
}

char *_str_pred_mode(int pred_mode) {
  switch(pred_mode) {
    case Intra_4x4: return "Intra_4x4";
    case Intra_16x16: return "Intra_16x16";
    case Pred_L0: return "Pred_L0";
    case Pred_L1: return "Pred_L1";
    case BiPred: return "BiPred";
    case Direct: return "Direct";
    default: return "n/a";
  }
}

void _dump_mb_mode(mb_mode *mb) {
  printf("MB: %s, %d parts %dx%d [%s,%s], i16=%d, cbp: C=%d L=%d\n",
         _str_mb_type(mb->mb_type),mb->NumMbPart,
         mb->MbPartWidth,mb->MbPartHeight,
         _str_pred_mode(mb->MbPartPredMode[0]),
         _str_pred_mode(mb->MbPartPredMode[1]),
         mb->Intra16x16PredMode,
         mb->CodedBlockPatternChroma,mb->CodedBlockPatternLuma);
}

int main(int argc, char *argv[]) {
  mb_mode mb;
  decode_mb_mode(&mb,I_SLICE,7); _dump_mb_mode(&mb);
  decode_mb_mode(&mb,P_SLICE,17);_dump_mb_mode(&mb);
  decode_mb_mode(&mb,P_SLICE,2); _dump_mb_mode(&mb);
  return 0;
}

